package com.whlilong.jxc.purcharsmanager.editor;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.nebula.widgets.datechooser.DateChooserCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;

import com.swtdesigner.SWTResourceManager;
import com.whlilong.jxc.print.IconSource;
import com.whlilong.jxc.print.PDocument;
import com.whlilong.jxc.print.PHLine;
import com.whlilong.jxc.print.PTableBoxProvider;
import com.whlilong.jxc.print.PTextBox;
import com.whlilong.jxc.print.PVSpace;
import com.whlilong.jxc.print.PrintPreview;
import com.whlilong.jxc.print.SWTPTable;

/**
 * @author auzn
 * 购销结算单
 *
 */
public class PurcharsSellEditor extends AbstractEditor {
	
	private Text textBusinessName;
	private Text textBookId;
	private Text textBase;
	private Text textUser;
	private Text textAuditing;
	private Combo comboBusinessid;
	private DateChooserCombo dateChooserCombo;
	private Combo combo;
	private Combo combo_1;
	private Combo combo_2;
	private DateChooserCombo dateChooserCombo_1;
	private Table table;
	private Combo combo1;


	public PurcharsSellEditor() {
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * @wbp.parser.entryPoint
	 */
	public Control createGroupText(Composite parent){
		Composite container = new Composite(parent, SWT.NONE);
		final GridLayout gl = new GridLayout(1, false);
		container.setLayout(gl);
		
		createBook(container);
		createTableViewer(container);
		return container;
		
	}

	/**
	 * @param parent
	 */
	private void createBook(Composite parent) {
		Composite composite = new Composite(parent, SWT.BORDER);
		GridData gd_composite = new GridData(SWT.LEFT, SWT.CENTER, false,
				false, 1, 1);
		composite.setLayoutData(gd_composite);
		GridLayout gl_composite = new GridLayout(7, false);
		gl_composite.marginRight = 100;
		gl_composite.marginLeft = 20;
		gl_composite.horizontalSpacing = 20;
		composite.setLayout(gl_composite);
		composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

		Label labelTitle = new Label(composite, SWT.NONE);
		labelTitle.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
		labelTitle.setForeground(Display.getDefault().getSystemColor(
				SWT.COLOR_DARK_GREEN));
		GridData gd_labelTitle = new GridData(SWT.FILL, SWT.CENTER, true, true,
				7, 1);
		gd_labelTitle.verticalIndent = 10;
		labelTitle.setLayoutData(gd_labelTitle);
		labelTitle.setAlignment(SWT.CENTER);
		labelTitle.setText("购销结算单");

		Label label = new Label(composite, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label.setText("供应商：");

		comboBusinessid = new Combo(composite, SWT.NONE);
		comboBusinessid.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));

		textBusinessName = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		textBusinessName.setEnabled(false);
		textBusinessName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));

		Label labelDate = new Label(composite, SWT.NONE);
		labelDate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		labelDate.setText("日期：");

		dateChooserCombo = new DateChooserCombo(composite, SWT.BORDER
				| SWT.READ_ONLY);
		dateChooserCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
				false, false, 1, 1));

		Label labelInbaseId = new Label(composite, SWT.NONE);
		labelInbaseId.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		labelInbaseId.setText("入库单号：");

		textBookId = new Text(composite, SWT.BORDER);
		textBookId.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));

		Label label_1 = new Label(composite, SWT.NONE);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_1.setText("仓库：");

		combo = new Combo(composite, SWT.NONE);
		combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1,
				1));

		textBase = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		textBase.setEnabled(false);
		textBase.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));

		Label label_2 = new Label(composite, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_2.setText("经办人：");

		combo1 = new Combo(composite, SWT.READ_ONLY);
		combo1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));

		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_3.setText("操作员：");

		textUser = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		textUser.setEnabled(false);
		textUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));

		Label label_4 = new Label(composite, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_4.setText("订货单号：");

		combo_2 = new Combo(composite, SWT.NONE);
		combo_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		new Label(composite, SWT.NONE);

		Label label_5 = new Label(composite, SWT.NONE);
		label_5.setText("有效日期：");

		dateChooserCombo_1 = new DateChooserCombo(composite, SWT.BORDER
				| SWT.READ_ONLY);
		GridData gd_dateChooserCombo_1 = new GridData(SWT.FILL, SWT.CENTER,
				false, false, 1, 1);
		gd_dateChooserCombo_1.widthHint = 100;
		dateChooserCombo_1.setLayoutData(gd_dateChooserCombo_1);

		Label label_6 = new Label(composite, SWT.NONE);
		label_6.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		label_6.setText("审核人：");

		textAuditing = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
		textAuditing.setEnabled(false);
		textAuditing.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
	}

	private void createTableViewer(Composite parent) {
		Composite composite = new Composite(parent, SWT.BORDER);
		GridLayout gl = new GridLayout(4, false);
		gl.marginRight = 10;
		composite.setLayout(gl);
		composite.setLayoutData(new GridData(GridData.FILL_BOTH));

		tableViewer = new TableViewer(composite, SWT.BORDER | SWT.H_SCROLL
				| SWT.FULL_SELECTION);
		tableViewer.setUseHashlookup(true);

		GridData gd = new GridData(GridData.FILL_BOTH);
		gd.horizontalSpan = 4;
		table = tableViewer.getTable();
		table.setLayoutData(gd);
		table.setToolTipText("点击单元格对数据进行修改！");
		// 设置行高
		table.addListener(SWT.MeasureItem, new Listener() {
			public void handleEvent(Event event) {

				event.height = 20;
			}
		});

	}
	@Override
	public void addInfo() {
		// TODO Auto-generated method stub

	}

	@Override
	public void create() {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete() {
		// TODO Auto-generated method stub

	}

	@Override
	public void print() {
		// TODO Auto-generated method stub
		final PDocument doc = new PDocument("print");

		PTextBox t;

		t = new PTextBox(doc);

		t.setText("武汉立隆客商信息");

		new PVSpace(doc, 0.5);
		new PHLine(doc, 0.02, SWT.COLOR_RED);
		new PVSpace(doc, 0.5);

		// create the table
		SWTPTable swttable = new SWTPTable(doc);
		swttable.setTable(table);
		swttable.setBoxProvider(new PTableBoxProvider());
		
		PrintPreview pr = new PrintPreview(null, "信息打印", IconSource
				.getImage("print"), doc);
		pr.onPrint();
	}

	@Override
	public void refresh() {
		// TODO Auto-generated method stub

	}

	@Override
	public void save() {
		// TODO Auto-generated method stub

	}

	@Override
	public void search() {
		// TODO Auto-generated method stub

	}

	@Override
	public void searchByCondition() {
		// TODO Auto-generated method stub

	}

	@Override
	public void preprint() {
		// TODO Auto-generated method stub
		final PDocument doc = new PDocument("print");

		PTextBox t;

		t = new PTextBox(doc);

		t.setText("武汉立隆客商信息");

		new PVSpace(doc, 0.5);
		new PHLine(doc, 0.02, SWT.COLOR_RED);
		new PVSpace(doc, 0.5);

		// create the table
		SWTPTable swttable = new SWTPTable(doc);
		swttable.setTable(table);
		swttable.setBoxProvider(new PTableBoxProvider());
		
		PrintPreview pr = new PrintPreview(null, "信息打印", IconSource
				.getImage("print"), doc);
		pr.open();
	}

}
